using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Jamila2.Tools;

public partial class GonzalesToolsPublicTransport : System.Web.UI.Page
{

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected bool ReadOnly = false;

    #region MandatoryMessage
    protected string MandatoryMessage
    {
        get
        {
            return ViewState["MandatoryMessage"].ToString();
        }

        set
        {
            ViewState["MandatoryMessage"] = value;
        }
    }
    #endregion

    #region NonNegativeMessage
    protected string NonNegativeMessage
    {
        get
        {
            return ViewState["NonNegativeMessage"].ToString();
        }

        set
        {
            ViewState["NonNegativeMessage"] = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        if (!IsPostBack)
        {
            if (Request.QueryString["NoEdit"] != null && Request.QueryString["NoEdit"].CompareTo("1") == 0)
            {
                this.ReadOnly = true;
            }

            this.PageComponentSetup();
            this.SwitchLanguage();
        }

        this.GenerateWarningMessage();
    }

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        this.Button_Submit.Attributes["onclick"] = "if (Validate()) {parent.ModalWindow.hide(); } return false;";
        this.Button_Cancel.Attributes["onclick"] = "if (PassParameter()) {parent.ModalWindow.hide(); } return false;";


        if (this.ReadOnly)
        {
            this.Button_Submit.Visible = false;
        }
    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_Cost.Text = CurLanguageFactory.DisplayValue("Cost");
                this.Label_Destination.Text = CurLanguageFactory.DisplayValue("Destination");
                this.Label_From.Text = CurLanguageFactory.DisplayValue("From");
                this.Label_Message.Text = CurLanguageFactory.DisplayValue("Message");
                this.Label_Purpose.Text = CurLanguageFactory.DisplayValue("Purpose");
                this.Label_Title.Text = CurLanguageFactory.DisplayValue("Title");
                this.Label_To.Text = CurLanguageFactory.DisplayValue("To");
                this.Label1.Text = CurLanguageFactory.DisplayValue("Label1");

                this.Button_Cancel.Text = CurLanguageFactory.DisplayValue("Cancel");
                this.Button_Submit.Text = CurLanguageFactory.DisplayValue("Submit");

                this.MandatoryMessage = CurLanguageFactory.DisplayValue("MandatoryMessage");
                this.NonNegativeMessage = CurLanguageFactory.DisplayValue("NonNegativeMessage");
            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesToolsTaxi.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region GenerateWarningMessage
    public void GenerateWarningMessage()
    {
        StringBuilder JSBuilder = new StringBuilder();
        JSBuilder.AppendLine("<script language='javascript'>");
        JSBuilder.AppendLine("var MandatoryMessage = '" + this.MandatoryMessage + "';");
        JSBuilder.AppendLine("var NonNegativeMessage = '" + this.NonNegativeMessage + "';");

        JSBuilder.AppendLine("</script>");

        // done, generate on the page
        if (!this.ClientScript.IsClientScriptBlockRegistered("GenerateWarningMessage"))
        {
            this.ClientScript.RegisterClientScriptBlock(Type.GetType("System.String"), "GenerateWarningMessage", JSBuilder.ToString());
        }
    }
    #endregion

}
